package com.example.demo_mvvm.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.example.demo_mvvm.R;
import com.example.demo_mvvm.entity.VideoEntity;
import com.example.demo_mvvm.viewmodel.VideoViewModel;

import java.util.List;

public class VideoActivity extends AppCompatActivity {
    private VideoViewModel mViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_video);
        mViewModel = new ViewModelProvider(this).get(VideoViewModel.class);

        //订阅数据
        mViewModel.liveData.observe(this, new Observer<List<VideoEntity>>() {
            @Override
            public void onChanged(List<VideoEntity> videoEntities) {
                Toast.makeText(VideoActivity.this, "请求成功"+videoEntities.size(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void getVideo(View view) {
        mViewModel.video(1);
    }
}